<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ECharts 3D Bar Chart</title>
    <script src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>
</head>
<body>
    <div id="main" style="width: 100%; height: 600px;"></div>
    <script type="text/javascript">
        let name = ['测试一','测试二','测试三','测试四','测试五','测试六','测试七','测试八','测试九'];
        let value = [1, 45, 24, 6, 37, 42, 45, 67, 9];
        let value1 = [21, 35, 44, 61, 74, 2, 45, 47, 92];
        let toolTims = null;
        const offsetX = 8;
        const offsetY = 4;

        const CubeLeft = echarts.graphic.extendShape({
            shape: { x: 0, y: 0 },
            buildPath: function (ctx, shape) {
                const xAxisPoint = shape.xAxisPoint;
                const c0 = [shape.x, shape.y];
                const c1 = [shape.x - offsetX, shape.y - offsetY];
                const c2 = [xAxisPoint[0] - offsetX, xAxisPoint[1] - offsetY];
                const c3 = [xAxisPoint[0], xAxisPoint[1]];
                ctx.moveTo(c0[0], c0[1]).lineTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).closePath();
            },
        });

        const CubeRight = echarts.graphic.extendShape({
            shape: { x: 0, y: 0 },
            buildPath: function (ctx, shape) {
                const xAxisPoint = shape.xAxisPoint;
                const c1 = [shape.x, shape.y];
                const c2 = [xAxisPoint[0], xAxisPoint[1]];
                const c3 = [xAxisPoint[0] + offsetX, xAxisPoint[1] - offsetY];
                const c4 = [shape.x + offsetX, shape.y - offsetY];
                ctx.moveTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).lineTo(c4[0], c4[1]).closePath();
            },
        });

        const CubeTop = echarts.graphic.extendShape({
            shape: { x: 0, y: 0 },
            buildPath: function (ctx, shape) {
                const c1 = [shape.x, shape.y];
                const c2 = [shape.x + offsetX, shape.y - offsetY];
                const c3 = [shape.x, shape.y - offsetX];
                const c4 = [shape.x - offsetX, shape.y - offsetY];
                ctx.moveTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).lineTo(c4[0], c4[1]).closePath();
            },
        });

        echarts.graphic.registerShape('CubeLeft', CubeLeft);
        echarts.graphic.registerShape('CubeRight', CubeRight);
        echarts.graphic.registerShape('CubeTop', CubeTop);

        const chart = echarts.init(document.getElementById('main'));

        const option = {
            backgroundColor: '#333',
            legend: {
                icon: "circle",
                left: '20px',
                top: '10px',
                itemWidth: 16,
                itemHeight: 16,
                itemGap: 20,
                textStyle: { fontSize: 14, color: "#fff" },
                data: ["累计作业", "在施"],
            },
            title: { text: '', left: 'center', textStyle: { color: '#2B7BD6' } },
            tooltip: { trigger: 'item' },
            grid: { top: "8%", left: "5%", right: "5%", bottom: "5%", containLabel: true },
            xAxis: {
                type: 'category',
                data: name,
                axisLine: { show: true, lineStyle: { color: '#2B7BD6' } },
                axisTick: { show: false },
                axisLabel: { fontSize: 14, interval: 0, textStyle: { color: '#FFF', fontSize: 12 } },
            },
            yAxis: {
                name: '',
                type: 'value',
                axisLine: { show: true, lineStyle: { color: '#2B7BD6' } },
                splitLine: { show: true, lineStyle: { type: 'dashed', color: 'rgba(20, 153, 255, 1)' } },
                axisTick: { show: false },
                axisLabel: { fontSize: 14, textStyle: { color: '#FFF', fontSize: 12 } },
            },
            series: [
                {
                    name: '累计作业',
                    type: 'custom',
                    // stack: "Ad",
                    renderItem: (params, api) => {
                        const location = api.coord([api.value(0), api.value(1)]);
                        return {
                            type: 'group',
                            x: -20,
                            children: [
                                {
                                    type: 'CubeLeft',
                                    shape: { api, xValue: api.value(0), yValue: api.value(1), x: location[0], y: location[1], xAxisPoint: api.coord([api.value(0), 0]) },
                                    style: {
                                        fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                            { offset: 0, color: 'rgba(2, 93, 196, 1)' },
                                            { offset: 1, color: 'rgba(0, 155, 217, 1)' },
                                        ]),
                                    },
                                },
                                {
                                    type: 'CubeRight',
                                    shape: { api, xValue: api.value(0), yValue: api.value(1), x: location[0], y: location[1], xAxisPoint: api.coord([api.value(0), 0]) },
                                    style: {
                                        fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                            { offset: 0, color: 'rgba(2, 93, 196, 1)' },
                                            { offset: 1, color: 'rgba(115, 246, 255, 1)' },
                                        ]),
                                    },
                                },
                                {
                                    type: 'CubeTop',
                                    shape: { api, xValue: api.value(0), yValue: api.value(1), x: location[0], y: location[1], xAxisPoint: api.coord([api.value(0), 0]) },
                                    style: {
                                        fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                            { offset: 0, color: 'rgba(28, 240, 255, 1)' },
                                            { offset: 1, color: 'rgba(201, 251, 255, 1)' },
                                        ]),
                                    },
                                },
                            ],
                        };
                    },
                    data: value,
                },
                {
                    name: '在施',
                    type: 'custom',
                    // stack: "Ad",
                    renderItem: (params, api) => {
                        const location = api.coord([api.value(0), api.value(1)]);
                        return {
                            type: 'group',
                            x: 1,
                            children: [
                                {
                                    type: 'CubeLeft',
                                    shape: { api, xValue: api.value(0), yValue: api.value(1), x: location[0], y: location[1], xAxisPoint: api.coord([api.value(0), 0]) },
                                    style: {
                                        fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                            { offset: 0, color: 'rgba(10, 148, 72, 1)' },
                                            { offset: 1, color: 'rgba(11, 255, 136, 1)' },
                                        ]),
                                    },
                                },
                                {
                                    type: 'CubeRight',
                                    shape: { api, xValue: api.value(0), yValue: api.value(1), x: location[0], y: location[1], xAxisPoint: api.coord([api.value(0), 0]) },
                                    style: {
                                        fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                            { offset: 0, color: 'rgba(0, 255, 132, 1)' },
                                            { offset: 1, color: 'rgba(117, 255, 172, 1)' },
                                        ]),
                                    },
                                },
                                {
                                    type: 'CubeTop',
                                    shape: { api, xValue: api.value(0), yValue: api.value(1), x: location[0], y: location[1], xAxisPoint: api.coord([api.value(0), 0]) },
                                    style: {
                                        fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                            { offset: 0, color: 'rgba(14, 221, 147, 1)' },
                                            { offset: 1, color: 'rgba(147, 255, 198, 1)' },
                                        ]),
                                    },
                                },
                            ],
                        };
                    },
                    data: value1,
                },
            ],
        };

        chart.setOption(option);
    </script>
</body>
</html>
